package com.ykg.controller;

import com.ykg.annotation.PassToken;
import com.ykg.dto.EntrustDTO;
import com.ykg.enums.ResultEnum;
import com.ykg.interceptor.ScopeLevel;
import com.ykg.pojo.Entrust;
import com.ykg.service.ICleanShipService;
import com.ykg.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * TODO
 * 类(接口)：
 * Created on 9:09 2021/6/26.
 *
 * @Author: laobian
 * @Description:
 */
@Api(tags = "流动机械部Api")
@RestController
@RequestMapping("/api/machine")
public class MachineController {
    @Autowired
    private ICleanShipService cleanShipService;

    //@PassToken
    @ApiOperation("获取委托单列表")
    @GetMapping("/all")
    @ScopeLevel(value = 7)
    public ResultResponse findAll(){
        List<Entrust> entrusts = cleanShipService.getEntrustMachine();
        if(Objects.isNull(entrusts)){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse((entrusts));
    }

    //@PassToken
    @ApiOperation("获取委托单详情")
    @GetMapping("/entrust/{entrustId}")
    @ScopeLevel(value = 7)

    public  ResultResponse getEntrustInfo(@PathVariable(value = "entrustId") String entrustId){
        if(entrustId == null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        EntrustDTO entrustDTO = cleanShipService.getEntrustDetailed(entrustId);
        if(Objects.isNull(entrustDTO)){
            return  new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(entrustDTO);
    }


   // @PassToken
    @ApiOperation("完成清仓工作")
    @PostMapping("/finish")
    @ScopeLevel(value = 7)

    public  ResultResponse stowBelt(@RequestParam String entrustId){
        if(entrustId == null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status= cleanShipService.finishEntrustMachine(entrustId);
        if(status==0){
            return  new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(ResultEnum.SUCCESS);
    }

}
